import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CounterController extends GetxController {
  var count = 0.obs;  // 使用.obs 将变量变成响应式的

  void increment() {
    count++;
  }
}

class CounterScreen extends StatelessWidget {
  // 获取 Controller 实例
  final CounterController controller = Get.put(CounterController());

  CounterScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
 child: Column(
   children: [
     Obx(() {
       // Obx 是用于监听响应式变量的组件
       return Text(
         'Counter: ${controller.count}',
         style: TextStyle(fontSize: 30),
       );
     }),
  TextButton(onPressed:controller.increment,
   child: Text("Increment"))

   ],
 ),
      ),
    );
  }
}

// https://docs.flutter.dev/get-started/fundamentals/networking#introduction-to-retrieving-data-over-the-network
// https://docs.flutter.dev/cookbook/networking/fetch-data
// https://api.flutter.dev/flutter/painting/BoxDecoration-class.html

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: CounterScreen(),
    );
  }
}
